// 财务信息
<template>
	<page-meta :root-font-size="getRootFontSize()"></page-meta>	
	<view class="">
		<view class="topBox">
			<view class="status_bar"></view>
			<uni-nav-bar
				style="width: 750rpx; height: 44px; border-bottom: 1px solid #F2F2F2;"
				@clickRight="showSetUp"
				@clickLeft="goHome"
				color="#FDFDFD"
				:border="false"
				:shadow="false"
				background-color="#CD001B"
			>
				<view class="titleImg"><image style="width: 100%; height: 100%;" mode="scaleToFill" src="/static/icon/logo_ctw@3x.png"></image></view>
				<view slot="left">
					<view class="leftIconBox"><uni-icons type="arrowleft" color="#000" size="18"></uni-icons></view>
				</view>
				<view slot="right"><uni-icons type="bars" color="#FDFDFD" size="28"></uni-icons></view>
			</uni-nav-bar>
		</view>

		<view class="zhuti" :style="{ marginTop: topBar }">
			<!-- 标题 -->
			<view class="titleBox">
				<view class="titleBoxcenter">
					<text>{{ this.$t('modifyMM.ctwfont5') }}</text>
				</view>
			</view>
			<!-- 导出 -->
			<view class="daochuBox">
				<view class="daochuBoxL">
					<text>{{ this.$t('modifyMM.ctwfont0') }}:</text>
					<text style="margin-left: 5px; font-weight: 700;">{{ cardArrList.customerCode }}</text>
				</view>
				<view class="daochuBoxR">
					<button size="mini" class="searchBtn2" type="default">
						<uni-icons type="upload-filled" size="14" style="margin-right: 5px;"></uni-icons>
						Export
					</button>
				</view>
			</view>
			<view class="detailsBoxTop">
				<view class="detailsBoxTopTitle">
					<view class="detailsBoxTopTitleL">{{ this.$t('modifyMM.ctwfont1') }}</view>
					<view class="detailsBoxTopTitleR">CNY {{ cardArrList.overdraft }}</view>
				</view>
				<view class="detailsBoxTopTitle">
					<view class="detailsBoxTopTitleL">{{ this.$t('modifyMM.ctwfont2') }}</view>
					<view class="detailsBoxTopTitleR">CNY {{ cardArrList.availableCreditBalance }}</view>
				</view>
				<view class="detailsBoxTopTitle">
					<view class="detailsBoxTopTitleL">{{ this.$t('modifyMM.ctwfont3') }}</view>
					<view class="detailsBoxTopTitleR">CNY {{ cardArrList.materialAmount }}</view>
				</view>
				<view class="detailsBoxTopTitle">
					<view class="detailsBoxTopTitleL">{{ this.$t('modifyMM.ctwfont4') }}</view>
					<view class="detailsBoxTopTitleR">CNY {{ cardArrList.balance }}</view>
				</view>
				<!-- <view class="detailsBoxTopTitle">
					<view class="detailsBoxTopTitleL">czxczxc</view>
					<view class="detailsBoxTopTitleR">232312312312</view>
				</view> -->
				<!-- <view class="lineBox"></view>
				<view class="detailsBoxTopTitle">
					<view class="detailsBoxTopTitleL">czxczxc</view>
					<view class="detailsBoxTopTitleR">232312312312</view>
				</view>
				<view class="detailsBoxTopTitle">
					<view class="detailsBoxTopTitleL">czxczxc</view>
					<view class="detailsBoxTopTitleR">232312312312</view>
				</view> -->
			</view>
		</view>
		<!-- 设置 -->
		<uni-popup ref="SetUpPopup" type="center" :animation="false"><set-up-pages ref="showPopup" @closePopUp="closePopUp" /></uni-popup>
		<!-- 退出 -->
		<sign-out ref="signOutBox" />
	</view>
</template>

<script>
import setUpPages from '@/pages/setUpPages/index.vue';
import signOut from '@/pages/setUpPages/signOut.vue'; // 退出登录
import { getStorage } from '@/utils/setStorage.js';
import { codeMapFun } from '@/utils/codeMap.js';
import baseFont from '@/utils/baseFont.js';
export default {
	extends: baseFont,
	data: function() {
		return {
			topBarHeight: 0, // 导航栏高度
			back_k: 0,
			popupIsShow: false, // 打开设置的标识
			signOutShow: false, // 退出登录
			cardArrList: ''
		};
	},
	onShow() {
		this.getList();
	},
	onLoad() {
		// 拦截物理返回键
		this.goBackBox();
	},
	onUnload() {
		uni.$off('goBack_k', this.goBackBox2);
	},
	created() {
		const that = this;
		uni.getSystemInfo({
			success(res) {
				that.topBarHeight = res.statusBarHeight;
			}
		});
	},
	onHide() {
		this.$refs.SetUpPopup.close();
		this.popupIsShow = false;
		this.$refs.signOutBox.close();
	},
	components: { setUpPages, signOut },
	computed: {
		topBar() {
			let num = 0;
			num = this.topBarHeight + 64; // 44是顶部高度
			return num + 'px';
		}
	},
	methods: {
		// 返回home
		goHome() {
			// #ifdef APP-PLUS
			uni.redirectTo({
				url: '/pages/me/index'
			});
			// #endif
			// #ifdef H5
			this.$Router.push('/pages/me/index');
			// #endif
		},
		goBackBox() {
			// const that = this;
			uni.$on('goBack_k', this.goBackBox2);
		},
		goBackBox2(data) {
			this.back_k < 0 ? (this.back_k = 0) : (this.back_k = this.back_k);
			if (data) {
				let main = plus.android.runtimeMainActivity();
				if (this.back_k > 0) {
					this.back_k = 0;
					return main.moveTaskToBack(false);
					// return plus.runtime.quit();
				} else {
					const pages = getCurrentPages();
					if (pages.length === 1) {
						this.back_k++;
						setTimeout(() => {
							this.back_k--;
						}, 1000);
						// #ifdef APP-PLUS
						// uni.switchTab({
						// 	url: '/pages/me/index'
						// });
						// // #endif
						// // #ifdef H5
						// this.$Router.push('/pages/me/index');
						// // #endif
						// uni.showToast({
						// 	title: '再按一次退出应用',
						// 	icon: 'none',
						// 	duration: 1000
						// });
					} else {
						uni.navigateBack({
							delta: 1
						});
					}
				}
			}
		},
		// 获取数据
		async getList() {
			const user = JSON.parse(getStorage('userconter'));
			const params = {
				customerCode: user.customerCode,
				beginDate: this.formatDate(new Date() - 2592000000),
				endDate: this.formatDate(new Date())
			};
			const { data: res } = await this.$http(true, 'api/E3/paymentFreight', params, 'GET');
			if (res.errno === 0) {
				this.cardArrList = res.data;
			} else {
				const err = codeMapFun().find(item => item[res.errno]);
				if (err) {
					uni.showToast({
						title: err[res.errno],
						icon: 'none',
						position: 'top'
					});
				} else {
					uni.showToast({
						title: res.errmsg,
						icon: 'none',
						position: 'top'
					});
				}
			}
		},
		// 时间处理
		formatDate(value) {
			const dt = new Date(value);
			const y = dt.getFullYear();
			const m = (dt.getMonth() + 1 + '').padStart(2, 0);
			const d = (dt.getDate() + '').padStart(2, 0);
			return `${y}-${m}-${d}`;
		},
		// 打开设置
		showSetUp() {
			this.$refs.SetUpPopup.open('right');
			this.popupIsShow = true;
		},
		// 关闭设置
		closePopUp(val) {
			if (val) {
				this.$refs.SetUpPopup.close();
				this.popupIsShow = false;
			} else {
				this.$refs.SetUpPopup.close();
				this.popupIsShow = false;
				this.$refs.signOutBox.open();
				this.signOutShow = true;
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.titleImg {
	width: 60px;
	height: 30px;
	margin: 0 auto;
	border-radius: 50%;
	overflow: hidden;
}
.leftIconBox {
	width: 25px;
	height: 25px;
	background-color: #fff;
	border-radius: 50%;
	display: flex;
	justify-content: center;
	align-items: center;
	margin-left: 15px;
}
.topBox {
	position: fixed;
	top: 0;
	left: 0;
	z-index: 10;
	// 顶部部分
	.status_bar {
		height: var(--status-bar-height);
		background-color: #CD001B;
		width: 100%;
	}
}
.zhuti {
	padding: 0 15px;
	box-sizing: border-box;
	.lineBox {
		border-top: 1.5px solid #e35768;
		margin: 5px 0;
	}
	.titleBox {
		margin-bottom: 5px;
		display: flex;
		justify-content: center;
		.titleBoxcenter {
			width: 100%;
			height: 30px;
			line-height: 30px;
			border-radius: 5px;
			text-align: center;
			background-color: #f2f2f2;
		}
	}
	.daochuBox {
		padding: 15px 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.daochuBoxL {
			font-size: $uni-font-size-custom-e;
			color: #CD001B;
		}
		.daochuBoxR {
			display: flex;
			align-items: center;
			.searchBtn2 {
				background-color: #ffffff;
				padding: 0 15px;
				margin-right: 0px;
				line-height: 1.8;
			}
		}
	}
	.detailsBoxTop {
		padding: 10px 15px;
		box-sizing: border-box;
		border-radius: 3px;
		background-color: #fbfbfb;
		margin-bottom: 20px;
		overflow: hidden;
		box-shadow: 0 3px 5px 1px #e3e3e3;
		.detailsBoxTopTitle {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 50px;
			.detailsBoxTopTitleL {
				padding-left: 10px;
				font-size: $uni-font-size-custom-e;
				color: #424451;
			}
			.detailsBoxTopTitleR {
				padding-right: 10px;
				font-size: $uni-font-size-custom-d;
				color: #424451;
			}
		}
	}
}
</style>
